package com.jiawa.train.business.controller.admin;


import com.jiawa.train.business.req.TrainQueryReq;
import com.jiawa.train.business.req.TrainSaveReq;
import com.jiawa.train.business.resp.TrainQueryResp;
import com.jiawa.train.business.service.ITrainSeatService;
import com.jiawa.train.business.service.ITrainService;
import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.common.resp.PageResp;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车次 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-09-07
 */
@RestController
@RequestMapping("/admin/train")
@RequiredArgsConstructor
public class TrainAdminController {
    private final ITrainService trainService;
    private final ITrainSeatService trainSeatService;

    @PostMapping("/save")
    public CommonResp<Object> save(@Validated @RequestBody TrainSaveReq trainSaveReq) {
        trainService.save(trainSaveReq);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainQueryResp>> queryList(@Validated TrainQueryReq req) {
        PageResp<TrainQueryResp> pa = trainService.queryList(req);
        return new CommonResp<>(pa);
    }

    @GetMapping("/query-all")
    public CommonResp<List<TrainQueryResp>> queryAll() {
        List<TrainQueryResp> pa = trainService.queryAll();
        return new CommonResp<>(pa);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        trainService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/gen-seat/{trainCode}")
    public CommonResp<Object> queryAll(@PathVariable String trainCode) {
        trainSeatService.genTrainSeat(trainCode);
        return new CommonResp<>();
    }
}
